import { defHttp } from '/@/utils/http/axios';
import { PageResult } from '@/api/model/pageResult';
import { QueryShopProductVo } from '@/api/base-data/shop-product/model/queryShopProductVo';
import { QueryShopProductBo } from '@/api/base-data/shop-product/model/queryShopProductBo';
import { GetShopProductBo } from '@/api/base-data/shop-product/model/getShopProductBo';
import { SaveShopProductVo } from '@/api/base-data/shop-product/model/saveShopProductVo';

const baseUrl = '/basedata/shop/product';
const region = 'cloud-api';

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryShopProductVo): Promise<PageResult<QueryShopProductBo>> {
  return defHttp.get<PageResult<QueryShopProductBo>>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetShopProductBo> {
  return defHttp.get<GetShopProductBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 保存
 * @param params
 * @returns {Promise}
 */
export function save(params: SaveShopProductVo): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl,
      params: {
        shopId: params.shopId,
        productAll: params.productAll,
        productIds: params.productIds,
      },
    },
    {
      region,
    },
  );
}
